package cn.edu.ecut.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;

@WebServlet( name = "configure" , urlPatterns = "/configure/*" ,
             loadOnStartup = 1 ,
             initParams = { @WebInitParam(name="empno",value="8526") , @WebInitParam(name="ename",value="秋香")} )
public class ConfigureServlet extends HttpServlet {

    // javax.servlet.http.HttpServlet 继承了 javax.servlet.GenericServlet
    // javax.servlet.GenericServlet 类 实现了 Servlet 、ServletConfig 、Serializable 接口

    @Override
    public void init() throws ServletException {
        super.init();
        System.out.println( "初始化: " + this );
    }

    @Override
    protected void service(HttpServletRequest request , HttpServletResponse response )
            throws ServletException, IOException {
        String eno = this.getInitParameter( "empno" );
        String ename = this.getInitParameter( "ename" );
        response.setCharacterEncoding( "UTF-8" );
        response.setContentType( "text/html;charset=UTF-8" );
        response.getWriter().println( eno + " , " + ename );
    }

}
